/**
 * Copyright &copy; 2016-2017 <a href="https://www.lczyfz.com">联创智云</a> All rights reserved.
 */
package com.lczyfz.campusinfo.modules.campusinfohelp.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lczyfz.campusinfo.modules.campusinfohelp.entity.CampusinfoProblem;
import com.lczyfz.campusinfo.modules.campusinfohelp.service.CampusinfoProblemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.lczyfz.campusinfo.common.config.Global;
import com.lczyfz.campusinfo.common.persistence.Page;
import com.lczyfz.campusinfo.common.web.BaseController;
import com.lczyfz.campusinfo.common.utils.StringUtils;
import com.lczyfz.campusinfo.modules.campusinfohelp.entity.CampusinfoProDetail;
import com.lczyfz.campusinfo.modules.campusinfohelp.service.CampusinfoProDetailService;
import java.util.List;
/**
 * 问题详情Controller
 * @author zms
 * @version 2018-04-16
 */
@Controller
@RequestMapping(value = "${adminPath}/campusinfohelp/campusinfoProDetail")
public class CampusinfoProDetailController extends BaseController {

	@Autowired
	private CampusinfoProDetailService campusinfoProDetailService;
	@Autowired
	private CampusinfoProblemService campusinfoProblemService;
	@ModelAttribute
	public CampusinfoProDetail get(@RequestParam(required=false) String id) {
		CampusinfoProDetail entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = campusinfoProDetailService.get(id);
		}
		if (entity == null){
			entity = new CampusinfoProDetail();
		}
		return entity;
	}
	
	@RequiresPermissions("campusinfohelp:campusinfoProDetail:view")
	@RequestMapping(value = {"list", ""})
	public String list(CampusinfoProDetail campusinfoProDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoProDetail> page = campusinfoProDetailService.findPage(new Page<CampusinfoProDetail>(request, response), campusinfoProDetail);
		List<CampusinfoProDetail>  campusinfoProblems = campusinfoProDetailService.findList(campusinfoProDetail);
		model.addAttribute("campusinfoProblems", campusinfoProblems);
		model.addAttribute("page", page);
		return "modules/campusinfohelp/campusinfoProDetailList";
	}

	@RequiresPermissions("campusinfohelp:campusinfoProDetail:view")
	@RequestMapping(value = "form")
	public String form(CampusinfoProDetail campusinfoProDetail, Model model) {
		CampusinfoProblem campusinfoProblem = new CampusinfoProblem();
		List<CampusinfoProblem>  campusinfoProblems = campusinfoProblemService.findList(campusinfoProblem);
		model.addAttribute("campusinfoProblems", campusinfoProblems);
		model.addAttribute("campusinfoProDetail", campusinfoProDetail);
		return "modules/campusinfohelp/campusinfoProDetailForm";
	}

	@RequiresPermissions("campusinfohelp:campusinfoProDetail:edit")
	@RequestMapping(value = "save")
	public String save(CampusinfoProDetail campusinfoProDetail, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, campusinfoProDetail)){
			return form(campusinfoProDetail, model);
		}
		campusinfoProDetailService.save(campusinfoProDetail);
		addMessage(redirectAttributes, "保存问题详情成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfohelp/campusinfoProDetail/?repage";
	}
	
	@RequiresPermissions("campusinfohelp:campusinfoProDetail:edit")
	@RequestMapping(value = "delete")
	public String delete(CampusinfoProDetail campusinfoProDetail, RedirectAttributes redirectAttributes) {
		campusinfoProDetailService.delete(campusinfoProDetail);
		addMessage(redirectAttributes, "删除问题详情成功");
		return "redirect:"+Global.getAdminPath()+"/campusinfohelp/campusinfoProDetail/?repage";
	}
	@RequiresPermissions("campusinfohelp:campusinfoProblem:edit")
	@RequestMapping(value = "detail")
	public String detail(CampusinfoProDetail campusinfoProDetail, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<CampusinfoProDetail> page = campusinfoProDetailService.findPage(new Page<CampusinfoProDetail>(request, response), campusinfoProDetail);
		List<CampusinfoProDetail>  campusinfoProblems = campusinfoProDetailService.findList(campusinfoProDetail);
		model.addAttribute("campusinfoProblems", campusinfoProblems);
		model.addAttribute("page", page);
		return "modules/campusinfohelp/campusinfoProDetailList";
	}

}